package com.gzpi.hwgggh.controller;

import com.gzpi.hwgggh.entity.DWC;
import com.gzpi.hwgggh.service.DWCService;
import com.gzpi.hwgggh.service.DWGService;
import com.gzpi.hwgggh.sysenum.EnumErrorCode;
import com.gzpi.hwgggh.utils.Result;
import com.gzpi.hwgggh.vo.SearchConditionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @date : 2021-01-13 15:59
 **/
@RestController
@RequestMapping("DWC")
@CrossOrigin
public class DWCController {

    @Autowired
    private DWCService dwcService;

    /**
     * 获取拆除点位集合
     * @param searchConditionVo 筛选条件
     * @return
     */
    @RequestMapping(value = "/getDWCList.do")
    public Result getDWCList(SearchConditionVo searchConditionVo){
        try {
            return dwcService.selectDWCList(searchConditionVo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
    }

    /**
     * 拆除点位所有信息 （包含拆除广告牌信息）
     * @param id 点位编号
     * @param
     * @return
     */
    @RequestMapping(value = "/getCCDW.do")
    public Result getDWC(String id){
        try {
            return dwcService.selectDWC(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
    }

    /**
     * 编辑拆除点位信息
     * @param file 拆除图文件
     * @param dwcJson 拆除点位json数据
     * @param request
     * @return
     */
    @RequestMapping(value = "/editDWC.do",method = RequestMethod.POST)
    public Result editDWC(@RequestParam(value = "dwcfile",required = false) MultipartFile file, String dwcJson, HttpServletRequest request){
        try {
            return dwcService.updateDWC(file,dwcJson,request);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
    }

    @RequestMapping("/removeDWC")
    public Result removeDWC(String id){
        try {
            return dwcService.deleteDWC(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString(e.toString()));
        }
    }

}
